package com.czy.owner.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.bumptech.glide.load.resource.drawable.GlideDrawable;
import com.czy.owner.R;
import com.czy.owner.entity.MyOrderDetailModel;
import com.czy.owner.utils.glide.GlideUtils;
import java.util.List;

/**
 * Created by Administrator on 2017/3/21 0021.
 */

public class MyOrderDetailGoodAdapter extends BaseRecyclerAdapter<MyOrderDetailModel.GoodsItemListBean ,MyOrderDetailGoodAdapter.OrderDetailGoodHolder> {
     private Context context;
    public MyOrderDetailGoodAdapter(Context context, List<MyOrderDetailModel.GoodsItemListBean> list) {
        super(context, list);
        this.context = context;

    }

    @Override
    public void onBindViewHolder(OrderDetailGoodHolder holder, int position) {
        super.onBindViewHolder(holder, position);
        holder.bindData(data.get(position));
    }

    @Override
    public OrderDetailGoodHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new OrderDetailGoodHolder(layoutInflater.inflate(R.layout.item_order_detail_good, parent, false));
    }

    public class OrderDetailGoodHolder extends BaseRecyclerAdapter.ViewHolder{
        private ImageView imgGoodPic;
        private TextView tvGoodName;
        private TextView tvGoodJine;
        private TextView tvBuyNumber;
        public OrderDetailGoodHolder(View itemView) {
            super(itemView);
            imgGoodPic = (ImageView)itemView.findViewById(R.id.img_good_pic);
            tvGoodName = (TextView)itemView.findViewById(R.id.tv_good_name);
            tvGoodJine = (TextView)itemView.findViewById(R.id.tv_good_jine);
            tvBuyNumber = (TextView)itemView.findViewById(R.id.tv_buy_number);



        }
        public void bindData(MyOrderDetailModel.GoodsItemListBean model){
            try {
                tvGoodName.setText(model.getItemName());
                tvGoodJine.setText("￥"+ String.format("%.2f",model.getPrice()));
                tvBuyNumber.setText("x "+model.getCount());
                GlideUtils.loadImage(context, model.getLogo(), imgGoodPic, new GlideUtils.ImageLoadListener<String, GlideDrawable>() {
                    @Override
                    public void onLoadingComplete(String uri, ImageView view, GlideDrawable resource) {

                    }

                    @Override
                    public void onLoadingError(String source, Exception e) {

                    }
                },R.mipmap.default_icon,R.mipmap.default_icon);
            }catch (Exception e){

            }


        }
    }
}
